package tools;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import entity.Backend_user;
import entity.Dev_user;

public class LoginInterceptor implements HandlerInterceptor{

	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("最后执行！！！一般用于释放资源！！");
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		System.out.println("Action执行之后，生成视图之前执行！！");
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {

		
		Backend_user user = (Backend_user) request.getSession().getAttribute("userSession");
		Dev_user devUser = (Dev_user) request.getSession().getAttribute("devUserSession");
		if(user!=null) {
			return true;
		}else if(devUser!=null) {
			return true;
		}else{
		System.out.println("<----------拦截---------->");
		response.sendRedirect(request.getContextPath()+"/403.jsp");
		return false;
		}
	}

}
